package com.example.home.metro.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.home.R;
import com.example.home.metro.activity.PathMessageDetail;
import com.example.home.metro.bean.PathMessageDetailBean;


public class PathMessageDetailAdapter extends RecyclerView.Adapter<PathMessageDetailAdapter.ViewHolder> {

    private Context context;
    private PathMessageDetailBean.DataBean data;


    public PathMessageDetailAdapter(PathMessageDetail context, PathMessageDetailBean.DataBean data) {
        this.context = context;
        this.data = data;
    }

    public void updateData(PathMessageDetailBean.DataBean newData) {
        this.data = newData;
        notifyDataSetChanged();
    }


    @NonNull
    @Override
    public PathMessageDetailAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.landmark_item,null);
        return new PathMessageDetailAdapter.ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull PathMessageDetailAdapter.ViewHolder holder, int position) {
        holder.name.setText(data.getMetroStepList().get(position).getName());
        holder.sequence.setText(String.valueOf(data.getMetroStepList().get(position).getSeq()));
        // 根据是否为当前站点设置颜色
        String currentStationName = data.getMetroStepList().get(holder.getAdapterPosition()).getName();
        if (currentStationName != null && currentStationName.equals(data.getRunStationsName())) {
            holder.name.setTextColor(Color.RED);
        } else {
            holder.name.setTextColor(Color.BLACK);
        }
    }


    @Override
    public int getItemCount() {
        return data.getMetroStepList() == null ? 0 : data.getMetroStepList().size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        private TextView sequence;
        private TextView name;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            sequence = itemView.findViewById(R.id.sequence);
            name = itemView.findViewById(R.id.name);
        }
    }
}


